package com.itfreer.gis.server.vector.generate.pipeline;

import org.geotools.geometry.jts.GeometryClipper;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;

import com.itfreer.gis.server.vector.generate.Pipeline;

/**
 * 简单切割接口
 */
public class Clip extends Pipeline {

	private final Envelope clippingEnvelope;

	public Clip(Envelope clippingEnvelope) {
		this.clippingEnvelope = clippingEnvelope;
	}

	@Override
	protected Geometry _run(Geometry geom) throws Exception {
		GeometryClipper clipper = new GeometryClipper(clippingEnvelope);
		try {
			return clipper.clip(geom, true);
		} catch (Exception e) {
			// 不健壮
			return clipper.clip(geom, false); // use non-robust clipper
		}
	}
}
